
from flask import request
from . import app_user
from conn_mysql import MysqlApi


@app_user.route('/register', methods=['POST'])
def register():

    phone = request.form.get('phone')
    verify_code = request.form.get('verify_code')
    pass_word_one = request.form.get('pass_word_one')
    pass_word_two = request.form.get('pass_word_two')

    if not all([phone, verify_code, pass_word_one, pass_word_two]):

        return {
                "status": -1,
                "errorCode": 3,
                "errorMsg": '请检查你的参数，有参数不合法',
                "resultBody": None,
            }

    with MysqlApi() as m:

        result_verify = m.verify_phone(phone, verify_code)

    if result_verify['status'] != 1:#当验证没有通过时

        return result_verify

    if pass_word_one != pass_word_two:

        return {
                "status": -1,
                "errorCode": 4,
                "errorMsg": '两次密码不一致，请重新输入',
                "resultBody": None,
            }

    with MysqlApi() as m:

        m.insert_user(phone, pass_word_one)

    return {
        "status": 1,
        "errorCode": None,
        "errorMsg": None,
        "resultBody": "注册成功",
    }
    


    
    

    

